#!/bin/sh

set -e
set -o xtrace

export DEBIAN_FRONTEND=noninteractive

cat > "/etc/sysctl.d/10-postgresql-performance.conf" << _EOF_
# See 'http://www.postgresql.org/docs/9.6/static/kernel-resources.html'
# for best practices.
# It is recommended to disable memory overcommit,
# but the Python interpreter may require it on smaller flavors.
# We therefore stick with the heuristic overcommit setting.
vm.overcommit_memory=0
_EOF_

apt-get --allow-unauthenticated -y install libpq-dev postgresql-12 postgresql-server-dev-12 postgresql-client-12

pgsql_conf=/etc/postgresql/12/main/postgresql.conf
sed -i "/listen_addresses/c listen_addresses = '*'" ${pgsql_conf}

systemctl restart postgresql

# Install the native Python client.
pip3 install psycopg2
